#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年4月1日

@author: chenyongbing
'''
import sys,os,commands,re
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]


dfiles = os.listdir(current_dir)

macs = {
'8c:29:37:0f:28:48',
'a4:5e:60:11:42:9f',
'44:d8:84:1c:2c:d2',
'54:9f:13:d8:f6:8b',
'20:64:32:d3:5f:fc'
        }
startTime = '2015-09-18 16:30'
endTime = '2015-09-18 17:00'


for dfile in dfiles:
    if not re.search('.txt',dfile):continue
    device = re.sub('.txt','',dfile)
    commands.getstatusoutput('mkdir %s'%device)
    for mac in macs:
        mfile = re.sub(':','',mac)
        fr = open('%s/%s.txt'%(device,mfile),'w')
        #commands.getstatusoutput('cat %s | grep "%s" > %s/%s.txt'%(dfile,device,device,mfile))
        for line in open(dfile).read().split('\n'):
            #2015-04-08.048d3861cd40.8c:21:0a:f3:d2:ff.16:08:50.-30.2015-04-08 16:08:55
            lineList = line.split('.')
            if len(lineList)<3:continue
            if lineList[2]!=mac:continue
            day = lineList[0]
            if day[:4] == '1970':
                stime = lineList[-1][11:]
            else:
                stime = lineList[3]
            
            if day == startTime.split(' ')[0] and stime < startTime.split(' ')[1]:continue
            if day == endTime.split(' ')[0] and stime > endTime.split(' ')[1]:continue
            #if stime<startTime:continue
            #if stime > endTime:continue
            fr.write(line+'\n')
        fr.close()
            